package com.joysuch.wwyt.datadump.biz.condition;

import cn.zlg.common.datadump.condition.CustomQueryConditionBuilder;
import com.joysuch.wwyt.core.entity.dsl.QBaseUser;
import com.joysuch.wwyt.core.service.BaseUserService;
import com.joysuch.wwyt.edu.entity.dsl.QEduQuestion;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.SimpleExpression;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class EduQuestionDumpCreateTimeConditionBuilder implements CustomQueryConditionBuilder {

    @Autowired
    private BaseUserService baseUserService;

    @Override
    public Predicate build(String name, SimpleExpression propertyPath, Object value) {
        Date d = (Date) value;
        LocalDate ld = LocalDate.fromDateFields(d);
        QEduQuestion q = QEduQuestion.eduQuestion;
        return q.createTime.goe(ld.toDate()).and(q.createTime.before(ld.plusDays(1).toDate()));
    }
}
